package com.yejign.quartzdemo;

import org.quartz.impl.StdSchedulerFactory;
import org.quartz.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TestScheduler {
    public static void main(String[] args) throws Exception {

        // 1，定义任务调度实例, 并与TestJob绑定
        JobDetail job = JobBuilder.newJob(TestJob.class)
            .withIdentity("testJob", "testJobGroup")
            .build();

        // 2，定义触发器, 会马上执行一次, 接着5秒执行一次
        Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity("testTrigger", "testTriggerGroup")
            .startNow()
            .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5))
            .build();

        // 3，获取任务调度的实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        // 4，使用触发器调度任务的执行
        scheduler.scheduleJob(job, trigger);

        // 5，开启任务
        scheduler.start();
    }
}